package com.example.designpatterns.memento;

/**
 * 备忘录模式演示类
 */
public class MementoDemo {
    public static void main(String[] args) {
        // 创建原发器
        Originator originator = new Originator();
        
        // 创建管理者
        Caretaker caretaker = new Caretaker();
        
        // 设置状态并保存
        originator.setState("状态1");
        caretaker.addMemento(originator.createMemento());
        
        originator.setState("状态2");
        caretaker.addMemento(originator.createMemento());
        
        originator.setState("状态3");
        caretaker.addMemento(originator.createMemento());
        
        // 恢复状态
        System.out.println("\n===== 恢复状态 =====");
        originator.restoreFromMemento(caretaker.getMemento(0)); // 恢复到状态1
        originator.restoreFromMemento(caretaker.getMemento(1)); // 恢复到状态2
        originator.restoreFromMemento(caretaker.getMemento(2)); // 恢复到状态3
    }
} 